package bTree.LeetCode;

public class 乘积最大子数组 {
    public int maxProduct(int[] nums) {
        int result = nums[0];
        int length = nums.length;
        int []dpMax=new int[length+1];
        int[]dpMin=new int[length+1];
        dpMin[1]=nums[0];
        dpMax[1]=nums[0];
        for (int i = 2; i <=length; i++) {
            int a=dpMax[i-1]*nums[i-1];
            int b=dpMin[i-1]*nums[i-1];
            dpMax[i]=Math.max(Math.max(a,b),nums[i-1]);
            dpMin[i]=Math.min(Math.min(a,b),nums[i-1]);
            result=Math.max(result,dpMax[i]);
        }
return result;

    }
}